import com.kuang.dao.UserMapper;
import com.kuang.pojo.User;
import com.kuang.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

public class MyBatis {

    @Test
    public  void test(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();

        UserMapper mapper = sqlSession.getMapper(UserMapper.class);

        User user = mapper.quertUserById(2);
        System.out.println(user);

        //mapper.updateUser(new User(2,"111111","1222"));

        sqlSession.clearCache();//手动清理缓存

        System.out.println("*******************");

        User user2 = mapper.quertUserById(2);
        System.out.println(user2);

        sqlSession.close();
    }

    @Test
    public  void test2(){
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        SqlSession sqlSession2 = MybatisUtils.getSqlSession();

        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        UserMapper mapper2 = sqlSession2.getMapper(UserMapper.class);

        User user = mapper.quertUserById(2);
        System.out.println(user);
        sqlSession.close();

        System.out.println("********************");

        User user2 = mapper2.quertUserById(2);
        System.out.println(user2);
        System.out.println(user==user2);

        User user3= mapper2.quertUserById(2);
        System.out.println(user3);
        System.out.println(user2);

        User user4= mapper2.quertUserById(2);
        System.out.println(user3);

        sqlSession2.close();
    }

}
